<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 柠檬水找零钱 -->
    <script>
      var change = function (dollar) {
        let five = 0
        let ten = 0
        for (let i = 0; i < dollar.length; i++) {
          if (dollar[i] === 5) five++
          else if (dollar[i] === 10) {
            if (five === 0) return false
            ten++
            five--
          } else if (five > 0 && ten > 0) {
            five--
            ten--
          } else if (five >= 3) {
            five -= 3
          } else {
            return false
          }
        }
        return true
      }
      // console.log(change([5, 5, 5, 10, 20]))
      // console.log(change([5, 5, 10, 10, 20]))
      console.log(change(0, 0, 6, 12, 2))
    </script>
  </body>
</html>
